from app import db
from datetime import datetime

class VitalSigns(db.Model):
    __tablename__ = 'vital_signs'
    
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    record_date = db.Column(db.DateTime, default=datetime.utcnow)
    
    # 心血管指标
    heart_rate = db.Column(db.Integer)  # 心率
    blood_pressure_systolic = db.Column(db.Integer)  # 收缩压
    blood_pressure_diastolic = db.Column(db.Integer)  # 舒张压
    
    # 呼吸指标
    respiratory_rate = db.Column(db.Integer)  # 呼吸频率
    blood_oxygen = db.Column(db.Float)  # 血氧饱和度
    
    # 体温
    body_temperature = db.Column(db.Float)  # 体温
    
    def to_dict(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'record_date': self.record_date.isoformat(),
            'heart_rate': self.heart_rate,
            'blood_pressure_systolic': self.blood_pressure_systolic,
            'blood_pressure_diastolic': self.blood_pressure_diastolic,
            'respiratory_rate': self.respiratory_rate,
            'blood_oxygen': self.blood_oxygen,
            'body_temperature': self.body_temperature
        }